# ifndef __ShpWizard_H_
# define __ShpWizard_H_

# include "PtAlgo.h"
# include "RgnKind.h"
# include "LoadStatus.h"
# include "Transform.h"

struct CShpHdr;
class CTypeSet;
class CDatabaseTable;
class CTransliterator;

enum input_attr_t {
	iaComment      = 0,
	iaEndLevel     = 1,
	iaNumber       = 2,
	iaStreet       = 3,
	iaCity         = 4,
	iaRegion       = 5,
	iaCountry      = 6,
	iaZipCode      = 7,
	iaPhone        = 8,
	iaFax          = 9,
	iaEmail        = 10,
	iaWebPage      = 11,
	iaDescription  = 12,
	iaDirIndicator = 13,
	iaSpeedLimit   = 14,
	iaRouteClass   = 15,
	iaOneWay       = 16,
	iaToll         = 17,
	iaNoEmergency  = 18,
	iaNoDelivery   = 19,
	iaNoCar        = 20,
	iaNoBus        = 21,
	iaNoTaxi       = 22,
	iaNoPedestrian = 23,
	iaNoBicycle    = 24,
	iaNoTruck      = 25,
	iaLast
};

class CShpWizard {
  public:
	CShpWizard (
		const char * _strFileName, const CDatabaseTable & _dbt,
		RGN_KIND _Kind, bool _bEnableSelectKind,
		const rect_t & _box
	);

	LoadStatus_t Show ();

	RGN_KIND GetKind () const {return m_Kind;}
	const CTypeSet * GetTypeSet () const {return m_pTypeSet;}
	bool GetFromTypeField () const {return m_bFromTypeField;}
	WORD GetType () const {return m_wType;}
	size_t GetTypeField () const {return m_cTypeField;}

	size_t GetLabelField () const {return m_cLabelField;}
	bool GetOEM () const {return m_bOEM;}
	const CTransliterator * GetTransliterator () const {return m_pTransliterator;}

	void HideCoordinatesPage () {m_bEnableCoordinates = false;}
	void SetBox (const rect_t & _box) {m_box = _box;}
	void SetLL () {m_bInitLatLon = true;}
	void SetTM (float _fCentralMeridian, float _fFE, float _fFN) {
		m_bInitTransverseMercator = true;
		m_fCentralMeridian = _fCentralMeridian;
		m_fFE = _fFE;
		m_fFN = _fFN;
	}
	CTransformationBase * GetUnitTransformation  () const {return m_pUnitTransformation.get ();}
	CTransformationBase * GetDatumTransformation () const {return m_pDatumTransformation;}

	const std::vector<bool> & GetLevels () {return m_Levels;}
	size_t GetLevelsToImport () const {return m_cLevelsToImport;}

  private:
	//
	// The context of the wizard.
	//

	const string_t m_strFileName;
	const CDatabaseTable * const m_pDbt;

	const bool m_bEnableSelectKind;
	RGN_KIND m_Kind;

	bool m_bEnableCoordinates;
	rect_t m_box;

	//
	// The data used by pages internaly.
	//

	size_t m_cTypeIndex;
	HWND m_hType, m_hTypeField, m_hTypeFieldStatic;
	bool IsTypeDefined () const {return m_bFromTypeField ? m_cTypeField != -1 : m_cTypeIndex != -1;}

	static INT_PTR CALLBACK PageTypeProc   (HWND _hWnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam);
	static INT_PTR CALLBACK PageLabelsProc (HWND _hWnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam);
	static INT_PTR CALLBACK PageUnitsProc  (HWND _hWnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam);
	static INT_PTR CALLBACK PageLevelsProc (HWND _hWnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam);
	static INT_PTR CALLBACK ExtraProc      (HWND _hWnd, UINT _uMsg, WPARAM _wParam, LPARAM _lParam);

	void _PrepareDBFView (HWND _hDbfFields);
	void _FillDBFView    (HWND _hDbfFields);

	void _ResetExtraFields ();
	void _FindDefaultExtraFields ();
	void _FillExtraAttributes (HWND _hList, bool _bFull = true);
	void _SelectDbfColumn (HWND _hWnd, size_t _cField);

	static void UpdateCentralMeridian   (HWND _hWnd, int _cu, const CShpWizard * _pThis);
	static void UpdateTargetCoordinates (HWND _hWnd, CShpWizard * _pThis);

	//
	// The data gathered by wizard.
	//

	bool m_bCanceled;

	const CTypeSet * m_pTypeSet;
	bool m_bFromTypeField;
	WORD m_wType;
	size_t m_cTypeField;

	size_t m_cLabelField;
	bool m_bOEM;
	const CTransliterator * m_pTransliterator;

  public:
	size_t m_cFields [iaLast];

  private:
	bool m_bInitLatLon;
	bool m_bInitTransverseMercator;
	float m_fCentralMeridian;
	float m_fFE;
	float m_fFN;
	std::auto_ptr<CTransformationBase> m_pUnitTransformation;
	CTransformationBase * m_pDatumTransformation;
	
	std::vector<bool> m_Levels;
	size_t m_cLevelsToImport;
};

# endif // __ShpWizard_H_